﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Web;
using LitJson;

namespace He.Common
{
    public class JsonString
    {
        /// <summary>
        /// 输出错误信息
        /// </summary>
        /// <param name="message"></param>
        public static void ShowEditorError(string message)
        {
            Hashtable hash = new Hashtable();
            hash["error"] = 1;
            hash["message"] = message;
            HttpContext.Current.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
            HttpContext.Current.Response.Write(JsonMapper.ToJson(hash));
            HttpContext.Current.Response.End();
        }

        /// <summary>
        /// 输出正确信息
        /// </summary>
        /// <param name="fileUrl"></param>
        public static void ShowEditorSuccess(string fileUrl)
        {
            Hashtable hash = new Hashtable();
            hash["error"] = 0;
            hash["url"] = fileUrl;
            HttpContext.Current.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
            HttpContext.Current.Response.Write(JsonMapper.ToJson(hash));
            HttpContext.Current.Response.End();
        }
        /// <summary>
        /// 输出Json字符串
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="msgBox"></param>
        public static void EchoJson(int msg, string msgBox)
        {
            EchoJson(msg, msgBox, "");
        }

        /// <summary>
        /// 输出Json字符串
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="msgBox"></param>
        /// <param name="gotoUrl"></param>
        public static void EchoJson(int msg, string msgBox, string gotoUrl)
        {
            Hashtable hash = new Hashtable();
            hash["msg"] = msg;
            hash["msgbox"] = msgBox;
            hash["url"] = gotoUrl;

            string json = JsonMapper.ToJson(hash);

            HttpContext.Current.Response.Write(json);
        }

        /// <summary>
        /// 输出成功的Json字符串
        /// </summary>
        /// <param name="msgBox"></param>
        /// <param name="url"></param>
        public static void EchoSuccess(string msgBox, string url)
        {
            EchoJson(1, msgBox, url);
        }

        /// <summary>
        /// 输出失败的Json字符串
        /// </summary>
        /// <param name="msgBox"></param>
        public static void EchoError(string msgBox)
        {
            EchoJson(0, msgBox);
            HttpContext.Current.Response.End();
        }

        /// <summary>
        /// 输出失败的Json字符串
        /// </summary>
        /// <param name="msgBox"></param>
        /// <param name="url"></param>
        public static void EchoError(string msgBox, string url)
        {
            EchoJson(0, msgBox, url);
            HttpContext.Current.Response.End();
        }
    }
}
